from django.core.management.base import BaseCommand
from home.models import Banner, NavCategory
from django.utils import timezone

class Command(BaseCommand):
    help = '生成Banner和NavCategory的测试数据'

    def handle(self, *args, **options):
        # 清除现有数据
        Banner.objects.all().delete()
        NavCategory.objects.all().delete()

        # 生成NavCategory测试数据
        nav_categories = [
            {
                'name': '免费课',
                'display_name': '零基础免费课',
                'weight': 1,
                'is_active': True,
                'theme_color': '#1890FF',
                'show_countdown': False,
                'external_link': ''
            },
            {
                'name': '实战课',
                'display_name': '付费实战课程',
                'weight': 2,
                'is_active': True,
                'theme_color': '#F5222D',
                'show_countdown': False,
                'external_link': ''
            },
            {
                'name': '学位课',
                'display_name': '高级进阶课程',
                'weight': 3,
                'is_active': True,
                'theme_color': '#52C41A',
                'show_countdown': True,
                'external_link': ''
            }
        ]

        for nav_data in nav_categories:
            NavCategory.objects.create(**nav_data)
        self.stdout.write(self.style.SUCCESS('成功创建3个导航分类'))

        # 生成Banner测试数据
        banners = [
            {
                'title': '轮播图1',
                'link': 'https://www.example.com/1',
                'image': 'banner/python.jpg',
                'note': 'Python全栈开发课程',
                'is_show': True,
                'weight': 10,
                'is_deleted': False
            },
            {
                'title': '轮播图2',
                'link': 'https://www.example.com/2',
                'image': 'banner/java.jpg',
                'note': 'Java架构师课程',
                'is_show': True,
                'weight': 9,
                'is_deleted': False
            },
            {
                'title': '轮播图3',
                'link': 'https://www.example.com/3',
                'image': 'banner/go.jpg',
                'note': 'Go语言开发课程',
                'is_show': True,
                'weight': 8,
                'is_deleted': False
            }
        ]

        for banner_data in banners:
            Banner.objects.create(**banner_data)
        self.stdout.write(self.style.SUCCESS('成功创建3个轮播图')) 